package com.itcoon.cloud.framework.transform.assemble.validator;

import com.itcoon.cloud.framework.transform.constants.ComponentOrderConstants;
import com.itcoon.cloud.framework.transform.exception.AssembleException;
import com.itcoon.cloud.framework.transform.proxy.IProxy;
import com.itcoon.cloud.framework.transform.utils.TransformServiceUtils;

/**
 * @author Miaoxia Yu
 * @date 2020-11-05
 */
public class Transform4jProxyValidator implements SourceValidator{
    @Override
    public boolean support(Object source) {
        return TransformServiceUtils.isAssembleProxy(source.getClass());
    }

    @Override
    public void validate(Object source, Class<?> originClass) {
        Class<?> sourceTargetClass = TransformServiceUtils.getProxyOrigin((IProxy<?, ?>) source);
        if (!sourceTargetClass.isAssignableFrom(originClass)) {
            throw new AssembleException(String.format("Illegal Source Proxy ,it required sourceClass '%s',but not found", originClass));
        }
    }

    @Override
    public int getOrder() {
        return ComponentOrderConstants.ASSEMBLE_SOURCE_VALIDATOR_MIN;
    }
}
